<!--
 * @Author: your name
 * @Date: 2021-08-03 13:36:05
 * @LastEditTime: 2021-08-12 13:26:42
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \getHome (2)\src\components\discounts\amend.vue
-->
<!--热门商品列表-->

<template>
  <div>
    <div class="herdertop">
      <img src="../../assets/top.png" alt="" class="topImg" />
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>通知管理</el-breadcrumb-item>
        <el-breadcrumb-item>热门商品列表</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="center">
      <div class="hander">热门商品列表</div>
      <div class="entirety">
        <div class="search">
          <!--  账号状态搜索信息 -->

          <div class="demo-input-suffix">
            通知类型

            <el-select
              clearable
              v-model="noticeType"
              placeholder="请选择"
              @change="onChangeStripe"
            >
              <el-option
                v-for="item in business"
                :key="item.dictCode"
                :label="item.dictName"
                :value="item.dictCode"
              >
              </el-option>
            </el-select>
          </div>
          <div class="news">
            <el-dialog :title="msg" :visible.sync="dialogFormVisible">
              <!--修改-->
              <el-form :model="Updata" ref="Updata" v-if="msg === '修改通知'">
                <el-form-item label="通知标题:" prop="msgTitle">
                  <el-input
                    style="width: 50%; margin-bottom: 10px; margin-left: 10px"
                    v-model="Updata.msgTitle"
                    placeholder="  请输入模板标题"
                  ></el-input>
                </el-form-item>

                <el-form-item label="通知内容:" prop="msgContent">
                  <el-input
                    style="width: 50%; margin-bottom: 10px; margin-left: 10px"
                    type="textarea"
                    v-model="Updata.msgContent"
                    placeholder="输入模板内容"
                  ></el-input>
                </el-form-item>
                <el-form-item label="通知发送:" prop="tempSwitch">
                  <el-checkbox-group v-model="Updata.sendType">
                    <el-checkbox
                      label="同时发送手机消息栏通知"
                      true-label="2"
                      false-label="1"
                      name="tempSwitch"
                    ></el-checkbox>
                  </el-checkbox-group>
                </el-form-item>
                <el-form-item style="text-align: right">
                  <el-button @click="dialogFormVisible = false"
                    >取 消</el-button
                  >
                  <el-button
                    style="background-color:#fd804c;color: #fff;"
                    @click="submitForm"
                    >确定</el-button
                  >
                </el-form-item>
              </el-form>
            </el-dialog>
          </div>
        </div>
      </div>
      <!--  员工列表栏位-->

      <div class="entirety">
        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="id" label="序号">
            <template slot-scope="scope">
              <div>
                {{ scope.row.id }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="subMsgTypeName" label="发送节点">
            <template slot-scope="scope">
              <div>
                {{ scope.row.subMsgTypeName }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="msgContent" label="通知内容">
            <template slot-scope="scope">
              <div>
                {{ scope.row.msgContent }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="noticeTypeName" label="通知类型">
            <template slot-scope="scope">
              <div>
                {{ scope.row.noticeTypeName }}
              </div>
            </template>
          </el-table-column>

          <el-table-column prop="tempSwitch" label="通知状态">
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.tempSwitch"
                :active-value="1"
                :inactive-value="0"
                active-text="开启"
                inactive-text="关闭"
                @change="switchChange($event, scope.row)"
                active-color="#fb8053"
                inactive-color="#dcdfe6"
              >
              </el-switch>
            </template>
          </el-table-column>
          <el-table-column fixed="right" label="操作">
            <template slot-scope="scope">
              <el-button
                @click="isDialog('修改通知', scope.row)"
                style="color: #fc9e76;"
                type="text"
                size="small"
              >
                修改
              </el-button>
              <!-- <el-button
                @click.native.prevent="isDel(scope.row.subMsgType)"
                   style="color: #fc9e76;"
                  type="text"
                size="small"
                style="color: #fd5e8e"
              >
                删除
              </el-button> -->
            </template>
          </el-table-column>
        </el-table>
        <div class="block">
          <div class="left"></div>
          <div class="right">
            <el-pagination
              layout="total, sizes, prev, pager, next, jumper"
              class="page"
              @size-change="sizeChangeHandle"
              @current-change="currentChangeHandle"
              :current-page="pageIndex"
              :page-size="pageSize"
              :total="total"
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      msg: "",

      pageIndex: 1,
      pageSize: 20,
      total: 0,
      dialogFormVisible: false,
      tableData: [],
      OrderMsgnodeList: [],
      id: "",
      userSearch: 0,
      subMsgTypes: "",
      noticeType: "",
      noticeTypes: "",
      business: [],
      Updata: {}
    };
  },
  activated() {
    this.DetailByPage();
    this.btii();
  },

  methods: {
    isRadio(e) {
      if (e !== this.noticeTypes) {
        this.Updata.subMsgType = "";
      } else {
        this.Updata.subMsgType = this.subMsgTypes;
      }
    },
    isDialog(type, data) {
      this.msg = type;

      if (data !== undefined && type == "修改通知") {
        this.DetailByPage();
        this.noticeTypes = data.noticeType;
        this.subMsgTypes = data.subMsgType;
        this.id = data.id;
        this.Updata = data;
      }
      this.dialogFormVisible = true;

      //console.log("num,,,,data.subMsgType s d,,", data.subMsgType);
    },

    submitForm() {
      this.$http({
        url: "/messageadmin/message/updateMessageTemplate",
        method: "POST",
        data: {
          id: this.id,
          msgContent: this.Updata.msgContent,
          msgTitle: this.Updata.msgTitle,
          noticeType: this.Updata.noticeType,
          sendType: this.Updata.sendType,
          subMsgType: this.Updata.subMsgType
        }
      })
        .then(res => {
          if (res.success === 0) {
            this.$message.error(res.errorMsg);
          } else {
            this.$message.success("修改成功");
            this.dialogFormVisible = false;

            (this.msg = ""), this.DetailByPage();
          }
        })
        .catch(() => {
          this.$message.error("修改失败");
        });
    },

    //删除
    isDel(subMsgType) {
      this.$confirm("是否删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$http({
            url: `/messageadmin/message/deleteMessageTemplate/${subMsgType}`,
            method: "GET"
          }).then(res => {
            if (res.success != 1) {
              this.$message.error(res.error);
            } else {
              this.$message.success("删除成功");

              this.DetailByPage();
            }
          });
        })
        .catch(() => {
          this.$message.error("删除失败");
        });
      this.DetailByPage();
    },

    // 更换状态数据
    onChangeStripe(val) {
      //console.log(val);

      this.noticeType = val || "";
      this.pageIndex = 1;

      this.DetailByPage();
    },
    //分页获取优惠券模板列表接口调用
    DetailByPage() {
      this.$http({
        url: `/messageadmin/message/fetchMessageTemplateList`,
        method: "GET",
        params: {
          noticeType: this.noticeType,
          page: this.pageIndex,
          size: this.pageSize
        }
      }).then(res => {
        this.tableData = res.list;

        this.total = parseInt(res.total);
      });
    },

    btii() {
      this.$http({
        url: "/messageadmin/message/fetchMessageTemplateNoticeType",
        method: "GET"
      }).then(res => {
        this.business = res.data.filter(Boolean);
      });
    },

    switchChange(e, data) {
      //console.log(e, "aing");
      //console.log(data, "data");

      let message = "";
      if (e == 1) {
        message = "启用成功 !";
        this.$http({
          url: `/messageadmin/message/controlMessageTemplateStatus`,
          method: "POST",
          data: {
            subMsgType: data.subMsgType,
            tempSwitch: 1
          }
        }).then(res => {
          if (res) return this.$message({ type: "success", message });
        });
      } else if (e == 0) {
        message = "停用成功 !";
        this.$http({
          url: `/messageadmin/message/controlMessageTemplateStatus`,
          method: "POST",
          data: {
            subMsgType: data.subMsgType,
            tempSwitch: 0
          }
        }).then(res => {
          if (res) return this.$message({ type: "success", message });
        });
      }
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;

      this.DetailByPage();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;

      this.DetailByPage();
    }
  }
};
</script>
<style scoped lang="scss">
.block {
  width: 100%;
  height: 70px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  padding: 0 10px 0 10px;
}
.left {
  font-size: 15px;
}
.hander {
  width: 100%;
  height: 50px;
  line-height: 50px;
  font-size: 20px;
  font-weight: 900;
}
.news {
  margin-left: 60%;
}
.entirety {
  width: 95%;
  margin: 10px;
  border: 7px solid #fafafa;
  border-radius: 10px;
  .basic {
    font-size: 18px;
    font-weight: 900;
    margin-top: 2%;
    margin-bottom: 1%;

    margin-left: 1%;
  }
}

.overall {
  width: 100%;
  height: auto;
  display: flex;

  justify-content: space-between;
  margin-top: 3%;
  .left {
    width: 20%;
    height: auto;
  }
  .right {
    width: 80%;
    height: auto;
  }
}
.demo-input-suffix {
  margin-left: 2%;
}
.select {
  width: 65%;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .dialog-footer,
  .choice {
    margin-left: 2%;
  }
}
.herdertop {
  height: 8vh;
  display: flex;
  align-items: center;
  padding: 0 20px;
  box-sizing: border-box;
}
.topImg {
  margin-right: 20px;
}
/deep/ .itemClass .el-form-item__content {
  width: 350px;
}
.userSearch {
  display: flex;
  /deep/ .el-input__inner {
    box-sizing: border-box;
    height: 40px;
    border-radius: 0;
    width: 132px;
    border: 1px solid #dcdfe6;
  }
  /deep/ .el-icon-arrow-up:before {
    position: relative;
    top: -4px;
  }
  /deep/ .el-button {
    height: 40px;
    border-radius: 0;
    background-color: #fff;
    border: 1px solid #dcdfe6;
    border-left: none;
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
    position: relative;
    .el-icon-search {
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }
  }
  /deep/ .el-input--suffix .el-input__inner {
    border-right: none;
  }
  /deep/ .el-input--suffix .el-input__inner {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
  }
}
.selects {
  width: 55%;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .dialog-footer,
  .choice {
    margin-left: 2%;
  }
}

/deep/ .but {
  background: #fd7097;
  color: #fff;
  margin-bottom: 1%;
}
</style>
